package org.finesys.common.security.client.properties;

import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.List;

@Data
@ConfigurationProperties("gitee")
public class GiteeProperties {
    //码云属性配置列表
    private List<Gitee> list;
    //默认码云的权限
    private String defaultRole;
    //默认AppId
    @Getter(AccessLevel.NONE)
    private String defaultAppId;

    public String getDefaultAppId() {
        if (StringUtils.hasText(defaultAppId)) {
            return defaultAppId;
        }

        return !CollectionUtils.isEmpty(list) ? list.get(0).getAppId() : null;
    }

    //内部类
    @Data
    public static class Gitee {
        //码云应用ID
        private String appId;
        //密钥
        private String secret;
        //重定向网址前缀
        private String redirectUriPrefix;
        //客户端ID
        private String clientId;
        //客户端密钥
        private String clientSecret;
        //范围
        private String scope;
        //登录成功后重定向URL的授权token name
        private String parameterName = "access_token";
        //登录成功后重定向URL
        private String successRedirectUrl;
        //应用授权服务器地址
        private String tokenUrl;

    }

}



